﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class PlatFormQuestion : System.Web.UI.Page
{
	private PX.Expert.ExpertComponent clsExpertComp = new PX.Expert.ExpertComponent();
	private PX.Chat.ChatComponent clsChatComp = new PX.Chat.ChatComponent();
	private PX.Config clsConfig = new PX.Config();
	private PX.OnLine.OnLineComponent clsOnLineComp = new PX.OnLine.OnLineComponent();

	/// <summary>
	/// 选择要提问的专家ID
	/// </summary>
	private int nSelectExpertID = 0;

	/// <summary>
	/// 提问者Session
	/// </summary>
	private string strQuestionSession = "";

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);

		strQuestionSession = Session.SessionID.ToString();

		btnQuestion.Click += new EventHandler(btnQuestion_Click);

		//idBody.Attributes.Add("onload", "goButtom('" + pPlatForm.ClientID.ToString()+ "')");
		//idBody.Attributes.Add("onunload", "MyClose()");
		idFrameChats.Attributes.Add("onload", "iFrameHeight('" + idFrameChats.ClientID.ToString() + "')");
		idFrameExperts.Attributes.Add("onload", "iFrameHeight('" + idFrameExperts.ClientID.ToString() + "')");

		clsOnLineComp.Add(Session.SessionID.ToString());
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		ShowSelectExpert();
		btnQuestion.Enabled = false;
		try
		{
			nSelectExpertID = Convert.ToInt32(Request["ExpertID"]);
		}
		catch (Exception ex)
		{
			nSelectExpertID = 0;
		}

		if (nSelectExpertID != 0)
		{
			btnQuestion.Enabled = true;
		}

		//ShowChat();
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>
	/// 提交问题
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void btnQuestion_Click(object sender, EventArgs e)
	{
		PX.Chat.Chat clsChat = new PX.Chat.Chat();
		PX.Expert.Expert clsExpert = new PX.Expert.Expert();

		clsExpert = (PX.Expert.Expert) clsExpertComp.GetOneByID(nSelectExpertID);
		
		clsChat.QuestionSession = strQuestionSession;
		clsChat.DateTime = System.DateTime.Now.ToString();
		clsChat.Chats = txtQuestion.Text;
		clsChat.ExpertID = nSelectExpertID;
		clsChat.QorA = clsConfig.nChat_Question;
		if (clsExpert != null)
		{
			clsChat.ExpertSession = clsExpert.OnLineSessionID;
		}

		clsChatComp.Add(clsChat);

		//ShowChat();
		txtQuestion.Text = "";
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>
	/// 显示要提问的专家
	/// </summary>
	private void ShowSelectExpert()
	{
		int nExpertID = 0;
		PX.Expert.Expert clsExpert = new PX.Expert.Expert();
		Label labSelectExpert = new Label();

		try
		{
			nExpertID = Convert.ToInt32(Request["ExpertID"]);
		}
		catch (Exception ex)
		{
			nExpertID = 0;
		}

		try
		{
			clsExpert = (PX.Expert.Expert)clsExpertComp.GetOneByID(nExpertID);
			if (clsExpert != null)
			{
				labSelectExpert.Text = "您对“" + clsExpert.Name + "”提问";
				pSelectExpert.Controls.Add(labSelectExpert);
			}
		}
		catch(Exception ex)
		{
		}
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	///// <summary>
	///// 显示交流记录
	///// </summary>
	//private void ShowChat()
	//{
	//        List<PX.Chat.Chat> list = new List<PX.Chat.Chat>();

	//        list = clsChatComp.Query(strQuestionSession);

	//        pPlatForm.Controls.Clear();

	//        for (int i = 0; i < list.Count; i++)
	//        {
						
	//                TextBox txtChat = new TextBox();
	//                Panel pOneChat = new Panel();
	//                Label labTitle = new Label();
	//                PX.Expert.Expert clsExpert = new PX.Expert.Expert();

	//                labTitle.CssClass = "oneChatTitle";
	//                pOneChat.CssClass = "oneChat";

	//                try
	//                {
	//                        clsExpert = clsExpertComp.Query(list[i].ExpertSession);
	//                }
	//                catch(Exception ex)
	//                {
	//                        clsExpert = null;
	//                }

	//                if (clsExpert != null)
	//                {
	//                        if (list[i].QorA == clsConfig.nChat_Question)
	//                        {
	//                                labTitle.Text = "您对“" + clsExpert.Name + "”提问";
	//                        }
	//                        else
	//                        {
	//                                labTitle.Text = "“" + clsExpert.Name + "”回答您";
	//                        }
	//                }

	//                pOneChat.Controls.Add(labTitle);

	//                txtChat.TextMode = TextBoxMode.MultiLine;
	//                //txtChat.Attributes.Clear();
	//                //txtChat.Attributes.Add("style", "width:250px;overflow-y:visible;");
	//                txtChat.CssClass = "textareaChats";
						
	//                txtChat.Text = list[i].Chats;

	//                //Literal lit = new Literal();

	//                //lit.Text = "<textarea style = \"width: 250px; overflow-y: visible;\">"+list[i].Chats+"</textarea>";

	//                pOneChat.Controls.Add(txtChat);

	//                pPlatForm.Controls.Add(pOneChat);
	//        }

	//        pPlatForm.Attributes.Add("onload", "goButtom('" + pPlatForm.ClientID.ToString() + "')");
	//}
	//////////////////////////////////////////////////////////////////////////////////////////////////////
}
